package com.niodata.dp.web;

import java.util.HashMap;
import java.util.Map;

public class PageInfo {

  private int start;
  private int stop;
  private boolean hasMore;
  private int pageIndex;
  private int pageSize;
  private int maxSeq;
  private int minSeq;

  public static PageInfo build(int count, int pageIndex, int pageSize, boolean hasMore) {
    PageInfo pageInfo = new PageInfo();
    pageInfo.setPageIndex(pageIndex);
    pageInfo.setStop((pageIndex - 1) * pageSize + count);
    pageInfo.setStart((pageIndex - 1) * pageSize + 1);
    pageInfo.setHasMore(hasMore);
    return pageInfo;
  }

  public static PageInfo build(int count, int pageIndex,
        int pageSize, boolean hasMore, int maxSeq, int minSeq) {
    PageInfo pageInfo = new PageInfo();
    pageInfo.setPageIndex(pageIndex);
    pageInfo.setStop((pageIndex - 1) * pageSize + count);
    pageInfo.setStart((pageIndex - 1) * pageSize + 1);
    pageInfo.setHasMore(hasMore);
    pageInfo.setMaxSeq(maxSeq);
    pageInfo.setMinSeq(minSeq);
    return pageInfo;
  }

  public int getStart() {
    return start;
  }

  public void setStart(int start) {
    this.start = start;
  }

  public int getStop() {
    return stop;
  }

  public void setStop(int stop) {
    this.stop = stop;
  }

  public boolean isHasMore() {
    return hasMore;
  }

  public void setHasMore(boolean hasMore) {
    this.hasMore = hasMore;
  }

  public int getPageIndex() {
    return pageIndex;
  }

  public void setPageIndex(int pageIndex) {
    this.pageIndex = pageIndex;
  }

  public int getPageSize() {
    return pageSize;
  }

  public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
  }

  public int getMaxSeq() {
    return maxSeq;
  }

  public void setMaxSeq(int maxSeq) {
    this.maxSeq = maxSeq;
  }

  public int getMinSeq() {
    return minSeq;
  }

  public void setMinSeq(int minSeq) {
    this.minSeq = minSeq;
  }

  public Map toMap() {
    Map<String, Object> map = new HashMap<>();
    map.put("pageIndex", pageIndex);
    map.put("pageSize", pageSize);
    map.put("count", stop - start);
    map.put("start", this.start);
    map.put("stop", this.stop);
    map.put("hasMore", hasMore);
    map.put("maxSeq", maxSeq);
    map.put("minSeq", minSeq);
    return map;
  }
}
